#include"LinerList.h"


/* 结构初始化 */
Status InitList(SqList *sqList)
{
    sqList->elem = (ElemType *)malloc(sizeof(ElemType) * LIST_INIT_SIZE);
    if(sqList->elem == NULL) {
        return ERROR;
    }
    sqList->length = 0;
    sqList->listSize = LIST_INIT_SIZE;

    return SUCCESS;
}

/* 销毁结构 */
void DestoryList(SqList *sqList)
{
    if(sqList == NULL){
        return;
    }
    free(sqList->elem);
    sqList->length = 0;
    sqList->listSize = 0;

    return;
}

/* 引用型操作 （不对线性表结构更改）*/
// 判空操作
Status ListEmpty(SqList sqList)
{
    return sqList.length == 0;
}

// 线性表当前长度
unsigned int ListLength(SqList sqList)
{
    return sqList.length;
}

// 线性表当前元素的前驱
Status PiiorElem(SqList sqList,ElemType curElem, ElemType *preElem)
{
    if(sqList.elem == NULL || sqList.length == 0) {
        return ERROR;
    }
    unsigned int u4Position = 0;
    if (GetElemPosition(sqList, curElem, u4Position) != SUCCESS) {
        return FAILURE;
    }
    if (u4Position <= 1) {
        return FAILURE;
    }
    *preElem = sqList.elem[u4Position -1];
    
    return SUCCESS;
}

// 当前元素的后继
NextElem(SqList sqList,ElemType curElem, ElemType &nextElem)
{

}

// 获取线性表 中第i个元素
Status GetElemFormPosition(SqList sqList,unsigned int position, ElemType *elem)
{

}

// 获取线性表中给定元素第一次出现的位置
Status GetElemPosition(SqList sqList, ElemType elem, unsigned int *u4Position)
{
    if(sqList.elem == NULL || sqList.length == 0) {
        *u4Position = 0;
        return ERROR;
    }
    for(unsigned int iCount = 0; iCount < sqList.length; iCount++) {
        if (CompareElemType(elem, sqList.elem[iCount]) == EQUAL) {
            *u4Position = iCount;
            return SUCCESS;
        }
    }
    *u4Position = 0;
    return FAILURE;
}

// 获取满足compare关系的第一个元素的位序
LocateElem(SqList sqList, ElemType &elem, compare())
{

}

// 依次对线性表的每个元素调用visit()
ListTraverse(SqList sqList, visit())
{

}

/* 加工型操作 （更改线性表的结构）*/
// 清空线性表（置为空表）
ClearList(SqList &sqList);

// 更改线性表中第i个位置的元素
SetElem(SqList sqList,unsigned int position, ElemType elem)
{

}

// 插入到position之前位置
ListInsert(SqList &sqList,unsigned int position, ElemType &elem)
{
    if (position <= 0 || position > sqList.) {
        return -1;
    }
    // 判断空间容量是否足够,不足需要扩容
    if (sqList.Length + 1 >= sqList.listSize) {

    }
    ElemType markElem = sqList[position];


}

// 删除操作
ListDelete(SqList &sqList, unsigned int position, ElemType &elem)
{

}